<?php defined('BASEPATH') || exit('No direct script access allowed');

/**
 * BuildingHome controller
 */
class BuildingHome extends Front_Controller
{

    /**
     * Constructor
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 3.0版本首页
     */
    public function index() {
        $get = $this->input->get();
        // 加载模型
        $this->load->model('hometop/hometop_model');
        $this->load->model('hotcity/hotcity_model');
        $this->load->model('area/area_model');
        $this->load->library('user_agent');

        // 获取首页轮播图
        $hometopArr = $this->hometop_model->select("id,city,imgtype,imgroute,url")->where("city=1 AND deleted = 0")->find_all();
        if (is_array($hometopArr)) {
            $building_phone_platform_code = building_phone_platform_code();
            foreach ($hometopArr as $key => $val) {
                $hometop[$building_phone_platform_code[$val->imgtype]][] = $val;
            }
        }
        $data['hometop'] = $hometop;
        // 是否移动端
        $data['is_mobile'] = $this->agent->is_mobile();
        // 根据板块获取所有已开通的城市
        $citiestmp = $this->area_model->select("area_id,area_name,code,plates")->where('active=1 and deleted=0')->find_all();

        $area_block_name = area_block_name();

        foreach ($citiestmp as $key => $val) {
            $cities[$area_block_name[$val->plates]][] = $val;
        }
        $data['cities'] = $cities;
        // 热门城市
        $data['hot_city'] = $this->hotcity_model->hotCity();
        // 加载视图
        $this->load->view('front/building/home', $data);
    }

    /**
     * 4.0版本首页
     */
    public function indexFour()
    {
        $get = $this->input->get();
        // 加载模型
        $this->load->model('hometop/hometop_model');
        $this->load->model('hotcity/hotcity_model');
        $this->load->model('area/area_model');
        $this->load->library('user_agent');
        $this->load->model('topic/topic_model');

        // 获取首页轮播图
        $hometopArr = $this->hometop_model->select("id,city,imgtype,imgroute,url")->where("city=1 AND deleted = 0")->find_all();
        if (is_array($hometopArr)) {
            $building_phone_platform_code = building_phone_platform_code();
            foreach ($hometopArr as $key => $val) {
                $hometop[$building_phone_platform_code[$val->imgtype]][] = $val;
            }
        }
        $data['hometop'] = $hometop;
        // 是否移动端
        $data['is_mobile'] = $this->agent->is_mobile();
        // 根据板块获取所有已开通的城市
        $citiestmp = $this->area_model->select("area_id,area_name,code,plates")->where('active=1 and deleted=0')->find_all();
        $area_block_name = area_block_name();
        foreach ($citiestmp as $key => $val) {
            $cities[$area_block_name[$val->plates]][] = $val;
        }
        $data['cities'] = $cities;
        // 热门城市
        $data['hot_city'] = $this->hotcity_model->hotCity();
        // 获取专题页信息
        $data['topics'] = $this->topic_model->where("deleted = 0 and status = 2")->order_by("id","DESC")->limit(3,0)->find_all();
        // dump($data['topics']);exit();
        // 加载视图
        $this->load->view('front/building/home4', $data);
    }
}